package com.bins.springboot.dubbo.api.thread;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Shop {
    private Lock lock = new ReentrantLock();

    private Integer goods = 100;

    public void get(){
        lock.lock();
        try {
            goods += 1;
        } finally {
            lock.unlock();
        }

    }
    public void buy(){
        lock.lock();
        try {
            goods -= 1;
        } finally {
            lock.unlock();
        }
    }

    public Integer getGoods(){
        return goods;
    }

    public void get1(){
        goods += 1;
    }
    public void buy1(){
        goods -= 1;
    }
}
